package com.bdqn.desiremall.serivce.goods;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.bdqn.desiremall.entity.Mall_Goods;
import com.bdqn.desiremall.entity.Mall_GoodsCategory;
import com.bdqn.desiremall.mapper.Mall_GoodsCategoryMapper;
import com.bdqn.desiremall.mapper.Mall_GoodsMapper;
import com.desiremall.util.MyBatisUtil;

public class GoodsSerivceImpl implements GoodsSerivce {
	SqlSession session = null;
	
    /**UC0501
     * �鿴��Ʒ�����Ը����Ʒ��Ʒ�ơ����ͺͱ�����ң�
     * �����ǰ��Ʒ���Բ鿴��Ʒ��ϸ��Ϣ
     * ��ƷͼƬ����Ʒ���⡢Ʒ�ơ��۸��ͺš���ɫ���ϼ�ʱ�䡢��Ʒ��������Ʒ��ء���Ʒ��š���Ʒ����
     */
	@Override
	public List<Mall_Goods> goodsView(Mall_Goods goods) {
		//��Ʒ����
		List<Mall_Goods> findGoods = null;
		try {
			session=MyBatisUtil.getSession();
			Mall_GoodsMapper mapper = session.getMapper(Mall_GoodsMapper.class);
			findGoods = mapper.findGoods(goods);
		} catch (Exception e) {
	         e.printStackTrace();
		}finally{
			MyBatisUtil.closeSqlSession(session);
		}
		return findGoods;
	}

	
      /**UC0801
       * �ϼ���Ʒ
       * �޸���Ʒ��B���ϼ�
       */
	@Override
	public boolean shelfGoods(Mall_Goods goods) {
	   try {
			session=MyBatisUtil.getSession();
			Mall_GoodsMapper mapper = session.getMapper(Mall_GoodsMapper.class);
			int i = mapper.modifyGoods(goods);
			if (i>0) {
				session.commit();
				return true;
			}
		
	} catch (Exception e) {
		session.rollback();
		  e.printStackTrace();
	}finally{
		MyBatisUtil.closeSqlSession(session);
	}
		return false;
	}

	 /**UC0801
     * �¼���Ʒ
     * �޸���Ʒ��B���¼�
     */
	@Override
	public boolean soldOut(Mall_Goods goods) {
		   try {
				session=MyBatisUtil.getSession();
				Mall_GoodsMapper mapper = session.getMapper(Mall_GoodsMapper.class);
				int i = mapper.modifyGoods(goods);
				if (i>0) {
					session.commit();
					return true;
				}
			
		} catch (Exception e) {
			session.rollback();
			  e.printStackTrace();
		}finally{
			MyBatisUtil.closeSqlSession(session);
		}
			return false;
	}
	
	
 /**UC0802
  * �޸���Ʒ��Ϣ
  */
	@Override
	public boolean modifyGoods(Mall_Goods goods) {
		   try {
					session=MyBatisUtil.getSession();
					Mall_GoodsMapper mapper = session.getMapper(Mall_GoodsMapper.class);
					int i = mapper.modifyGoods(goods);
					if (i>0) {
						session.commit();
						return true;
					}
				
			} catch (Exception e) {
				session.rollback();
				  e.printStackTrace();
			}finally{
				MyBatisUtil.closeSqlSession(session);
			}
				return false;
		
	}


@Override
public List<Mall_GoodsCategory> findGoodsCategoryView(int categoryId) {
	List<Mall_GoodsCategory> goodsCategoryList=null;
	try {
			session=MyBatisUtil.getSession();
			Mall_GoodsCategoryMapper mapper = session.getMapper(Mall_GoodsCategoryMapper.class);
			goodsCategoryList=mapper.findGoodsCategory(categoryId);
	} catch (Exception e) {
		session.rollback();
		  e.printStackTrace();
	}finally{
		MyBatisUtil.closeSqlSession(session);
	}
	return goodsCategoryList;
}

}
